package com.kma.summer2012.client.view.authorization;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import com.kma.summer2012.client.presenters.authorization.AuthorizationPresenter;
import com.kma.summer2012.client.styles.style2.Recources;

public class AuthorizationView extends Composite implements AuthorizationPresenter.Display {

    interface AuthorizationViewUiBinder extends UiBinder<Widget, AuthorizationView> {
    }

    private static AuthorizationViewUiBinder ourUiBinder = GWT.create(AuthorizationViewUiBinder.class);

    @UiField
    protected TextBox loginBox;

    @UiField
    protected PasswordTextBox passwordBox;

    @UiField
    protected Button loginButton;

    @UiField
    protected CheckBox showPassword;

    @UiField
    protected Label wrongPassword;

    @UiField
    protected Anchor passRecovery;

    @UiField
    protected DecoratorPanel panel;

    public AuthorizationView() {
        HTMLPanel rootElement = (HTMLPanel) ourUiBinder.createAndBindUi(this);
        panel.addStyleName(Recources.INSTANCE.styles().authorization());
        loginButton.addStyleName(Recources.INSTANCE.styles().Caption());
        initWidget(rootElement);

    }

    @Override
    public HasClickHandlers getLoginButton() {
        return loginButton;
    }

    @Override
    public HasKeyPressHandlers getKeyLoginButton() {
        return loginButton;
    }

    @Override
    public HasKeyPressHandlers getKeyLoginBox() {
        return loginBox;
    }

    @Override
    public HasKeyPressHandlers getKeyPasswordBox() {
        return passwordBox;
    }

    @Override
    public HasClickHandlers getPassRecovery() {
        return passRecovery;
    }

    @Override
    public String getLoginTextBox() {
        return loginBox.getValue();
    }

    @Override
    public String getPasswordTextBox() {
        return passwordBox.getValue();
    }

    @Override
    public void setPasswordTextBox(String text) {
        this.passwordBox.setValue(text);
    }

    @Override
    public void setLoginTextBox(String text) {
        this.loginBox.setValue(text);
    }

    @Override
    public CheckBox getShowPassword() {
        return showPassword;
    }

    @Override
    public void changePasswordTextBoxType() {
        if (this.passwordBox.getElement().getAttribute("type").equals("text")) {
            this.passwordBox.getElement().setAttribute("type", "password");
        } else {
            this.passwordBox.getElement().setAttribute("type", "text");
        }

    }

    @Override
    public void setTextWrongPassword(String text) {
        this.wrongPassword.setText(text);
    }

    public Widget asWidget() {
        return this;
    }

}